Skip to content

chore: add testcases for k8s packages #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2025
Merged

Conversation

liangyuanpeng
Copy link
Contributor

releated:

1. Please confirm that you have read the document before PR submitted

2. Contact Information(Optional)

If it is convenient, please provide your contact information so we can reach you when processing the PR:

  • Email:
  • HomePage:

@liangyuanpeng liangyuanpeng force-pushed the ut_k8s_pkg branch 4 times, most recently from 7776b2d to 2045484 Compare April 25, 2025 13:22
@liangyuanpeng
Copy link
Contributor Author

liangyuanpeng commented Apr 25, 2025

	error[E2G22]: TypeError
	  --> /home/runner/work/modules/modules/k8s/1.32/api/networking/v1/ingress_backend.k:22:16
	   |
	22 |     resource?: v1.TypedLocalObjectReference
	   |                ^ attribute 'TypedLocalObjectReference' not found in 'module 'k8s.apimachinery.pkg.apis.meta.v1''
	   |
	
	 [recovered]
	panic: 
	error[E2L23]: CompileError
	 --> /home/runner/work/modules/modules/k8s/1.32/api/networking/v1/ingress_backend.k:6:1
	  |
	6 | import api.core.v1
	  | ^ the name 'v1' is defined multiple times, 'v1' must be defined only once
	  |
	
	
	error[E2G22]: TypeError
	  --> /home/runner/work/modules/modules/k8s/1.32/api/networking/v1/ingress_backend.k:22:16
	   |
	22 |     resource?: v1.TypedLocalObjectReference
	   |                ^ attribute 'TypedLocalObjectReference' not found in 'module 'k8s.apimachinery.pkg.apis.meta.v1''

it's happenning on kcl-go v1.11.1,and i think change import api.core.v1 to import api.core.v1 as corev1 can fix it. I will update it on tomorrow or next week.

@liangyuanpeng
Copy link
Contributor Author

generate k8s 1.32.4 with the following changes: always imports package asName and asName always with corev1 and not v1, metav1 and not v1,applicable to all packages.

https://github.com/kcl-lang/kcl-openapi/blob/b80f946f1e1ce9ee5cef95377df39b6a336d3d1c/pkg/swagger/generator/model.go#L321-L327

++		strs := strings.Split(innerPkg, ".")
++		importpkg := strs[len(strs)-2] + strs[len(strs)-1]
		imp[sch.Pkg] = importStmt{
			ImportPath: innerPkg, // remove the root package name
--			AsName:     asName,
++			AsName:     importpkg,
			// MustAsName: asName != sch.Pkg[strings.LastIndex(sch.Pkg, ".")+1:],
			// if the package alias is conflict with other imports, use the `import as` syntax to resolve conflict.
--			MustAsName: asName != sch.Pkg[strings.LastIndex(sch.Pkg, ".")+1:],
++			MustAsName: true,
		}

And CI is green, so this PR can be merge and continue for k8s 1.33. @Peefy

@liangyuanpeng
Copy link
Contributor Author

cc @zong-zhe @He1pa

@Peefy
Copy link
Contributor

Peefy commented May 6, 2025

Good Job! Thank you!

@Peefy Peefy merged commit f74f8a5 into kcl-lang:main May 6, 2025
6 of 7 checks passed
@liangyuanpeng liangyuanpeng deleted the ut_k8s_pkg branch May 6, 2025 08:43
@liangyuanpeng
Copy link
Contributor Author

Due to main_test.go has changed, main.go fails to run. I will fix it. https://github.com/kcl-lang/modules/actions/runs/14854063178/job/41703108401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants